<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<script type="text/javascript">
	window.onload = function  () {
		var aDiv = document.getElementsByClassName('box');		//和querySelectorAll相比，这个是专门找className的，所以不加'.'
		/*
			IE8及以下不支持getElementsByClassName
		*/
		for (var i = 0; i < aDiv.length; i++) {
			aDiv[i].style.backgroundColor = 'red';
		};
	}
</script>
<body>
	<div id="div1" class="box">div</div>
	<div class="box">div</div>
</body>
</html>